<?php

namespace app\api\controller\User;

use think\Controller;
use think\Request;

class Record extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->UserModel = model('User.User');
        $this->RecordModel = model('Record');
    }

    //获取积分记录
    public function listData()
    {
        $userid = $this->request->param('userid', 0);
        $createtime = $this->request->param('createtime', 0);
        $User = $this->UserModel->find($userid);

        if (!$User) {
            $this->error('用户不存在');
        }
        $result = null;
        if (!empty($createtime)) {
            $STime = $createtime . '-1';
            $ETime = $createtime . '-30';
            $result = $this->RecordModel->where('userid', $userid)->whereTime('createtime', 'between', [$STime, $ETime])->order('createtime desc')->select();
        } else {
            $result = $this->RecordModel->where('userid', $userid)->order('createtime desc')->select();
        }

        if ($result == FALSE) {
            $this->error('查询失败');
        } else {
            $this->success('查询成功', null, $result);
        }
    }
}
